#region File Header
// Copyright (c) 2011, Stefan Stolz
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// 
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// 
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
// 
// * Neither the name of Sharp2City nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
#region using directives

using System.Collections.Generic;
using System.Diagnostics;
using System.Xml.Serialization;

#endregion

namespace Sharp2City
{
    [XmlRoot("server")]
    public sealed class XmlServer
    {
        #region private fields

        private int buildNumber;

        private string currentTime;

        private string startTime;

        private string version;

        private int versionMajor;

        private int versionMinor;

        #endregion

        #region public properties

        [XmlAttribute("buildNumber")]
        public int BuildNumber
        {
            get
            {
                return this.buildNumber;
            }
            set
            {
                this.buildNumber = value;
            }
        }

        [XmlAttribute("currentTime")]
        public string CurrentTime
        {
            get
            {
                return this.currentTime;
            }
            set
            {
                this.currentTime = value;
            }
        }

        [XmlAttribute("startTime")]
        public string StartTime
        {
            get
            {
                return this.startTime;
            }
            set
            {
                this.startTime = value;
            }
        }

        [XmlAttribute("version")]
        public string Version
        {
            get
            {
                return this.version;
            }
            set
            {
                this.version = value;
            }
        }

        [XmlAttribute("versionMajor")]
        public int VersionMajor
        {
            get
            {
                return this.versionMajor;
            }
            set
            {
                this.versionMajor = value;
            }
        }

        [XmlAttribute("versionMinor")]
        public int VersionMinor
        {
            get
            {
                return this.versionMinor;
            }
            set
            {
                this.versionMinor = value;
            }
        }

        #endregion
    }

    [XmlRoot("builds")]
    [DebuggerDisplay("Count: {count} - Next Href: {nextHref}")]
    public sealed class XmlBuildsCollection
    {
        #region private fields

        private readonly List<XmlBuildBasic> build = new List<XmlBuildBasic>();

        private int count;

        private string nextHref;

        #endregion

        #region public properties

        [XmlElement("build")]
        public List<XmlBuildBasic> Build
        {
            [DebuggerStepThrough]
            get
            {
                return (this.build);
            }
        }

        [XmlAttribute("count")]
        public int Count
        {
            [DebuggerStepThrough]
            get
            {
                return this.count;
            }
            [DebuggerStepThrough]
            set
            {
                this.count = value;
            }
        }

        [XmlAttribute("nextHref")]
        public string NextHref
        {
            [DebuggerStepThrough]
            get
            {
                return this.nextHref;
            }
            [DebuggerStepThrough]
            set
            {
                this.nextHref = value;
            }
        }

        #endregion
    }


    [XmlRoot("dependency-build")]
    public sealed class XmlDependencyBuild
    {
        #region private fields

        private string _buildTypeId;

        private string _href;

        private int _id;

        private string _number;

        private string _status;

        private string _webUrl;

        #endregion

        #region public properties
        
        [XmlAttribute("buildTypeId")]
        public string BuildTypeId
        {
            [DebuggerStepThrough]
            get
            {
                return this._buildTypeId;
            }
            [DebuggerStepThrough]
            set
            {
                this._buildTypeId = value;
            }
        }

        [XmlAttribute("href")]
        public string Href
        {
            [DebuggerStepThrough]
            get
            {
                return this._href;
            }
            [DebuggerStepThrough]
            set
            {
                this._href = value;
            }
        }

        [XmlAttribute("id")]
        public int Id
        {
            [DebuggerStepThrough]
            get
            {
                return this._id;
            }
            [DebuggerStepThrough]
            set
            {
                this._id = value;
            }
        }

        [XmlAttribute("number")]
        public string Number
        {
            [DebuggerStepThrough]
            get
            {
                return this._number;
            }
            [DebuggerStepThrough]
            set
            {
                this._number = value;
            }
        }

        [XmlAttribute("status")]
        public string Status
        {
            [DebuggerStepThrough]
            get
            {
                return this._status;
            }
            [DebuggerStepThrough]
            set
            {
                this._status = value;
            }
        }

        [XmlAttribute("webUrl")]
        public string WebUrl
        {
            [DebuggerStepThrough]
            get
            {
                return this._webUrl;
            }
            [DebuggerStepThrough]
            set
            {
                this._webUrl = value;
            }
        }

        #endregion

    }

    [XmlRoot("build")]
    public sealed class XmlBuildDetailed
    {
        #region private fields

        private XmlBuildType buildType = new XmlBuildType();

        private XmlPinInfo pinInfo;

        private string finishDate;

        private string href;

        private int id;

        private string number;

        private string startDate;

        private string status;

        private string statusText;

        private string webUrl;

        private bool pinned; 

        private List<XmlDependencyBuild> dependencyBuild = new List<XmlDependencyBuild>();

        private List<XmlTag> tags = new List<XmlTag>();

        #endregion

        #region public properties

        [XmlElement("buildType")]
        public XmlBuildType BuildType
        {
            [DebuggerStepThrough]
            get
            {
                return this.buildType;
            }
            [DebuggerStepThrough]
            set
            {
                this.buildType = value;
            }
        }

        [XmlElement("pinInfo")]
        public XmlPinInfo PinInfo
        {
            [DebuggerStepThrough]
            get
            {
                return this.pinInfo;
            }
            [DebuggerStepThrough]
            set
            {
                this.pinInfo = value;
            }
        }

        [XmlElement("dependency-build")]
        public List<XmlDependencyBuild> DependencyBuild
        {
            [DebuggerStepThrough]
            get
            {
                return (this.dependencyBuild);
            }
        }

        [XmlElement("tags")]
        public List<XmlTag> Tags
        {
            [DebuggerStepThrough]
            get
            {
                return (this.tags);
            }
        }

        [XmlElement("finishDate")]
        public string FinishDate
        {
            [DebuggerStepThrough]
            get
            {
                return this.finishDate;
            }
            [DebuggerStepThrough]
            set
            {
                this.finishDate = value;
            }
        }

        [XmlAttribute("href")]
        public string Href
        {
            [DebuggerStepThrough]
            get
            {
                return this.href;
            }
            [DebuggerStepThrough]
            set
            {
                this.href = value;
            }
        }

        [XmlAttribute("id")]
        public int Id
        {
            [DebuggerStepThrough]
            get
            {
                return this.id;
            }
            [DebuggerStepThrough]
            set
            {
                this.id = value;
            }
        }

        [XmlAttribute("number")]
        public string Number
        {
            [DebuggerStepThrough]
            get
            {
                return this.number;
            }
            [DebuggerStepThrough]
            set
            {
                this.number = value;
            }
        }

        [XmlElement("startDate")]
        public string StartDate
        {
            [DebuggerStepThrough]
            get
            {
                return this.startDate;
            }
            [DebuggerStepThrough]
            set
            {
                this.startDate = value;
            }
        }

        [XmlElement("statusText")]
        public string StatusText
        {
            [DebuggerStepThrough]
            get
            {
                return this.statusText;
            }
            [DebuggerStepThrough]
            set
            {
                this.statusText = value;
            }
        }

        [XmlAttribute("status")]
        public string Status
        {
            [DebuggerStepThrough]
            get
            {
                return this.status;
            }
            [DebuggerStepThrough]
            set
            {
                this.status = value;
            }
        }

        [XmlAttribute("webUrl")]
        public string WebUrl
        {
            [DebuggerStepThrough]
            get
            {
                return this.webUrl;
            }
            [DebuggerStepThrough]
            set
            {
                this.webUrl = value;
            }
        }

        [XmlAttribute("pinned")]
        public bool Pinned
        {
            [DebuggerStepThrough]
            get
            {
                return this.pinned;
            }
            [DebuggerStepThrough]
            set
            {
                this.pinned = value;
            }
        }

        #endregion
    }

    public sealed class XmlBuildBasic
    {
        #region private fields
        private string buildTypeId;

        private string href;

        private int id;

        private string number;

        private string status;

        private string webUrl;

        #endregion

        #region public properties

        [XmlAttribute("buildTypeId")]
        public string BuildTypeId
        {
            [DebuggerStepThrough]
            get
            {
                return this.buildTypeId;
            }
            [DebuggerStepThrough]
            set
            {
                this.buildTypeId = value;
            }
        }

        [XmlAttribute("href")]
        public string Href
        {
            [DebuggerStepThrough]
            get
            {
                return this.href;
            }
            [DebuggerStepThrough]
            set
            {
                this.href = value;
            }
        }

        [XmlAttribute("id")]
        public int Id
        {
            [DebuggerStepThrough]
            get
            {
                return this.id;
            }
            [DebuggerStepThrough]
            set
            {
                this.id = value;
            }
        }

        [XmlAttribute("number")]
        public string Number
        {
            [DebuggerStepThrough]
            get
            {
                return this.number;
            }
            [DebuggerStepThrough]
            set
            {
                this.number = value;
            }
        }

        [XmlAttribute("status")]
        public string Status
        {
            [DebuggerStepThrough]
            get
            {
                return this.status;
            }
            [DebuggerStepThrough]
            set
            {
                this.status = value;
            }
        }

        [XmlAttribute("webUrl")]
        public string WebUrl
        {
            [DebuggerStepThrough]
            get
            {
                return this.webUrl;
            }
            [DebuggerStepThrough]
            set
            {
                this.webUrl = value;
            }
        }

        #endregion
    }

    [XmlRoot("projects")]
    [DebuggerDisplay("Count: {projects.Count}")]
    public sealed class XmlProjects
    {
        #region private fields

        private readonly List<XmlProject> projects = new List<XmlProject>();

        #endregion

        #region public properties

        [XmlElement("project")]
        public List<XmlProject> Projects
        {
            get
            {
                return (this.projects);
            }
        }

        #endregion
    }

    public sealed class XmlBuilds
    {
        #region private fields

        private string href;

        #endregion

        #region public properties

        [XmlAttribute("href")]
        public string Href
        {
            [DebuggerStepThrough]
            get
            {
                return this.href;
            }
            [DebuggerStepThrough]
            set
            {
                this.href = value;
            }
        }

        #endregion
    }

    [XmlRoot("buildType")]
    public sealed class XmlDetailedBuildType
    {
        #region private fields

        private XmlBuilds builds;

        private string description;

        private string href;

        private string id;

        private string name;

        private string webUrl;

        private XmlVcsRootBuildType vcsRoot;

        #endregion

        #region public properties

        [XmlElement("builds")]
        public XmlBuilds Builds
        {
            [DebuggerStepThrough]
            get
            {
                return this.builds;
            }
            [DebuggerStepThrough]
            set
            {
                this.builds = value;
            }
        }

        [XmlElement("vcs-root")]
        public XmlVcsRootBuildType VcsRoot
        {
            [DebuggerStepThrough]
            get
            {
                return this.vcsRoot;
            }
            [DebuggerStepThrough]
            set
            {
                this.vcsRoot = value;
            }
        }


        [XmlAttribute("description")]
        public string Description
        {
            [DebuggerStepThrough]
            get
            {
                return this.description;
            }
            [DebuggerStepThrough]
            set
            {
                this.description = value;
            }
        }

        [XmlAttribute("href")]
        public string Href
        {
            [DebuggerStepThrough]
            get
            {
                return this.href;
            }
            [DebuggerStepThrough]
            set
            {
                this.href = value;
            }
        }

        [XmlAttribute("id")]
        public string Id
        {
            [DebuggerStepThrough]
            get
            {
                return this.id;
            }
            [DebuggerStepThrough]
            set
            {
                this.id = value;
            }
        }

        [XmlAttribute("name")]
        public string Name
        {
            [DebuggerStepThrough]
            get
            {
                return this.name;
            }
            [DebuggerStepThrough]
            set
            {
                this.name = value;
            }
        }

        [XmlAttribute("webUrl")]
        public string WebUrl
        {
            [DebuggerStepThrough]
            get
            {
                return this.webUrl;
            }
            [DebuggerStepThrough]
            set
            {
                this.webUrl = value;
            }
        }

        #endregion
    }

    public sealed class XmlBuildType
    {
        #region private fields

        private string href;

        private string id;

        private string name;

        private string projectId;

        private string projectName;

        private string webUrl;

        #endregion

        #region public properties

        [XmlAttribute("href")]
        public string Href
        {
            [DebuggerStepThrough]
            get
            {
                return this.href;
            }
            [DebuggerStepThrough]
            set
            {
                this.href = value;
            }
        }

        [XmlAttribute("id")]
        public string Id
        {
            [DebuggerStepThrough]
            get
            {
                return this.id;
            }
            [DebuggerStepThrough]
            set
            {
                this.id = value;
            }
        }

        [XmlAttribute("name")]
        public string Name
        {
            [DebuggerStepThrough]
            get
            {
                return this.name;
            }
            [DebuggerStepThrough]
            set
            {
                this.name = value;
            }
        }

        [XmlAttribute("projectId")]
        public string ProjectId
        {
            [DebuggerStepThrough]
            get
            {
                return this.projectId;
            }
            [DebuggerStepThrough]
            set
            {
                this.projectId = value;
            }
        }

        [XmlAttribute("projectName")]
        public string ProjectName
        {
            [DebuggerStepThrough]
            get
            {
                return this.projectName;
            }
            [DebuggerStepThrough]
            set
            {
                this.projectName = value;
            }
        }

        [XmlAttribute("webUrl")]
        public string WebUrl
        {
            [DebuggerStepThrough]
            get
            {
                return this.webUrl;
            }
            [DebuggerStepThrough]
            set
            {
                this.webUrl = value;
            }
        }

        #endregion
    }

    public sealed class XmlBuildTypes
    {
        #region private fields

        private readonly List<XmlBuildType> buildType = new List<XmlBuildType>();

        #endregion

        #region public properties

        [XmlElement("buildType")]
        public List<XmlBuildType> BuildType
        {
            get
            {
                return (this.buildType);
            }
        }

        #endregion
    }

    [DebuggerDisplay("Name: {name} Id: {id} Href: {href}")]
    [XmlRoot("project")]
    public sealed class XmlProject
    {
        #region private fields

        private bool archived;

        private XmlBuildTypes buildType;

        private string description;

        private string href;

        private string id;

        private string name;

        private string webUrl;

        #endregion

        #region public properties

        [XmlAttribute("archived")]
        public bool Archived
        {
            [DebuggerStepThrough]
            get
            {
                return this.archived;
            }
            [DebuggerStepThrough]
            set
            {
                this.archived = value;
            }
        }

        [XmlElement("buildTypes")]
        public XmlBuildTypes BuildType
        {
            [DebuggerStepThrough]
            get
            {
                return this.buildType;
            }
            [DebuggerStepThrough]
            set
            {
                this.buildType = value;
            }
        }

        [XmlAttribute("description")]
        public string Description
        {
            [DebuggerStepThrough]
            get
            {
                return this.description;
            }
            [DebuggerStepThrough]
            set
            {
                this.description = value;
            }
        }

        [XmlAttribute("href")]
        public string Href
        {
            [DebuggerStepThrough]
            get
            {
                return this.href;
            }
            [DebuggerStepThrough]
            set
            {
                this.href = value;
            }
        }

        [XmlAttribute("id")]
        public string Id
        {
            [DebuggerStepThrough]
            get
            {
                return this.id;
            }
            [DebuggerStepThrough]
            set
            {
                this.id = value;
            }
        }

        [XmlAttribute("name")]
        public string Name
        {
            [DebuggerStepThrough]
            get
            {
                return this.name;
            }
            [DebuggerStepThrough]
            set
            {
                this.name = value;
            }
        }

        [XmlAttribute("webUrl")]
        public string WebUrl
        {
            [DebuggerStepThrough]
            get
            {
                return this.webUrl;
            }
            [DebuggerStepThrough]
            set
            {
                this.webUrl = value;
            }
        }

        #endregion
    }

    [XmlRoot("tag")]
    public sealed class XmlTag
    {

        #region public properties

        [XmlElement("tag")]
        public string Tag
        {
            get;
            set;
        }

        #endregion
    }

    [XmlRoot("pinInfo")]
    public sealed class XmlPinInfo
    {

        #region public properties

        [XmlElement("text")]
        public string Text
        {
            get;
            set;
        }

        [XmlElement("timestamp")]
        public string Timestamp
        {
            get;
            set;
        }

        #endregion
    }

    [XmlRoot("property")]
    public sealed class XmlProperty
    {

        #region public properties

        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }

        [XmlAttribute("value")]
        public string Value
        {
            get;
            set;
        }

        #endregion
    }

    [XmlRoot("vcs-root")]
    public sealed class XmlVcsRootBasic
    {
        #region public properties

        [XmlAttribute("href")]
        public string Href
        {
            get;
            set;
        }

        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }

        #endregion
    }

    [XmlRoot("vcs-roots")]
    public sealed class XmlVcsRoots
    {
        #region private fields

        private readonly List<XmlVcsRootBasic> vcsRoots = new List<XmlVcsRootBasic>();

        #endregion

        #region public properties

        [XmlElement("vcs-root")]
        public List<XmlVcsRootBasic> VcsRoots
        {
            get
            {
                return (this.vcsRoots);
            }
        }

        #endregion
    }

    [XmlRoot("vcs-root")]
    public sealed class XmlVcsRootDetail
    {
        #region private fields

        private readonly List<XmlProperty> properties = new List<XmlProperty>();

        #endregion

        #region public properties

        [XmlAttribute("lastChecked")]
        public string LastChecked
        {
            get;
            set;
        }

        [XmlAttribute("status")]
        public string Status
        {
            get;
            set;
        }

        [XmlAttribute("vcsName")]
        public string VcsName
        {
            get;
            set;
        }

        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }

        [XmlAttribute("id")]
        public int Id
        {
            get;
            set;
        }

        [XmlArray(ElementName = "properties")]
        [XmlArrayItem(ElementName = "property")]
        public List<XmlProperty> Properties
        {
            get
            {
                return (this.properties);
            }
        }

        #endregion
    }

    [XmlRoot("vcs-root")]
    public sealed class XmlVcsRootBuildType
    {
        #region private fields

        private readonly List<XmlVcsRootEntry> vcsRootEntries = new List<XmlVcsRootEntry>();

        #endregion

        #region public properties

        [XmlElement(ElementName = "vcs-root-entry")]
        public List<XmlVcsRootEntry> VcsRootEntries
        {
            get
            {
                return (this.vcsRootEntries);
            }
        }

        #endregion
    }

    [XmlRoot("vcs-root-entry")]
    public sealed class XmlVcsRootEntry
    {

        #region public properties

        [XmlElement("vcs-root")]
        public XmlVcsRootBasic VcsRoot
        {
            get;
            set;
        }

        #endregion
    }

    [XmlRoot("users")]
    public sealed class XmlUsers
    {
        #region private fields

        private readonly List<XmlUserBasic> users = new List<XmlUserBasic>();

        #endregion

        #region public properties

        [XmlElement("user")]
        public List<XmlUserBasic> Users
        {
            get
            {
                return (this.users);
            }
        }

        #endregion
    }

    [XmlRoot("user")]
    public sealed class XmlUserBasic
    {
        #region public properties

        [XmlAttribute("username")]
        public string UserName
        {
            get;
            set;
        }

        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }

        [XmlAttribute("id")]
        public int Id
        {
            get;
            set;
        }

        [XmlAttribute("href")]
        public string Href
        {
            get;
            set;
        }

        #endregion
    }

    [XmlRoot("user")]
    public sealed class XmlUserDetail
    {
        #region private fields

        private readonly List<XmlGroupBasic> groups = new List<XmlGroupBasic>();

        #endregion

        #region public properties

        [XmlAttribute("username")]
        public string UserName
        {
            get;
            set;
        }

        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }

        [XmlAttribute("id")]
        public int Id
        {
            get;
            set;
        }

        [XmlAttribute("email")]
        public string Email
        {
            get;
            set;
        }

        [XmlAttribute("lastLogin")]
        public string LastLogin
        {
            get;
            set;
        }

        [XmlArray(ElementName = "groups")]
        [XmlArrayItem(ElementName = "group")]
        public List<XmlGroupBasic> Groups
        {
            get
            {
                return (this.groups);
            }

        }
        #endregion
    }

    [XmlRoot("groups")]
    public sealed class XmlGroups
    {
        #region private fields

        private readonly List<XmlGroupBasic> groups = new List<XmlGroupBasic>();

        #endregion

        #region public properties

        [XmlElement("group")]
        public List<XmlGroupBasic> Groups
        {
            get
            {
                return (this.groups);
            }
        }

        #endregion
    }

    [XmlRoot("group")]
    public sealed class XmlGroupBasic
    {
        #region public properties

        [XmlAttribute("key")]
        public string Key
        {
            get;
            set;
        }

        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }

        [XmlAttribute("href")]
        public string Href
        {
            get;
            set;
        }

        #endregion
    }

    [XmlRoot("group")]
    public sealed class XmlGroupDetail
    {
        #region private fields

        private readonly List<XmlUserBasic> users = new List<XmlUserBasic>();

        #endregion

        #region public properties

        [XmlAttribute("key")]
        public string Key
        {
            get;
            set;
        }

        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }

        [XmlAttribute("href")]
        public string Href
        {
            get;
            set;
        }

        [XmlArray(ElementName = "users")]
        [XmlArrayItem(ElementName = "user")]
        public List<XmlUserBasic> Users
        {
            get
            {
                return (this.users);
            }
        }

        #endregion
    }

}